package InetAdress;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class InputAdress02 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket=new ServerSocket(9999);
        System.out.println("等待连接！");
        Socket socket=serverSocket.accept();
        System.out.println(socket.getClass());
        InputStream inputStream= socket.getInputStream();
        byte[] b=new byte[1024];
        int n=0;
        while ((n=inputStream.read(b))!=-1){
            System.out.println(new String(b,0,n));
        }



        OutputStream outputStream=socket.getOutputStream();
        outputStream.write("hello,client".getBytes());
        socket.shutdownOutput();
        //必须关闭流和socket
        outputStream.close();
        socket.close();
        serverSocket.close();
        inputStream.close();
    }
}
